<?php
class UserModel extends Model {

    /**
     * UserModel class constructor.
     */
    function UserModel()
    {
        parent::Model();

    }

    /**
     * Method for inserting a new user account into the database.
     * An associative array with the indexes of 'username', 'password',
     * 'fname', 'lname', 'email', 'city', and 'state' must be passed as
     * an argument.
     * @param array $accountData
     */
    function addNewAccount($accountData)
    {
        $this->db->insert('users', $accountData);
    }

    /**
     * Method for determining if a duplicate username already exists
     * in the database.
     * @param string $username
     * @return boolean
     */
    function checkForDuplicate($username)
    {
        $this->db->where('username', $username);
        $query = $this->db->get('users');

        if($query->num_rows == 0)
                return true;
        else
            return false;
    }

    /**
     * Method for checking the existance of a user account within the
     * database.
     * @param string $username
     * @param string $password
     * @return boolean
     */
    function checkCredentials($username, $password)
    {
        $this->db->where('username', $username);
        $this->db->where('password', $password);
        $query = $this->db->get('users');

        if($query->num_rows == 1)
            return true;
        else
            return false;
    }

    /**
     * Method for retrieving data from the user table.
     * @param string $username
     * @return array
     */
    function getUserInfo($username)
    {
        $this->db->select('pk, fname, lname, email, city, state');
        $this->db->where('username', $username);
        $query = $this->db->get('users');

        $ret = $query->result_array();

        return $ret[0];
    }
}


?>
